package com.example.administrator.managesystem.view;

import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;


public class BaseDialogBuilder implements Parcelable {

    //两边间距
    public int interval = 48;
    //点击外部是否取消
    public boolean cancelOnTouch = true;
    //是否遮盖层透明度
    public boolean cancelCover;
    public int layoutId;
    public String title;
    public boolean needAnimal = true;

    protected BaseDialogBuilder() {}

    public static final Creator<BaseDialogBuilder> CREATOR = new Creator<BaseDialogBuilder>() {
        @Override
        public BaseDialogBuilder createFromParcel(Parcel in) {
            return new BaseDialogBuilder(in);
        }

        @Override
        public BaseDialogBuilder[] newArray(int size) {
            return new BaseDialogBuilder[size];
        }
    };

    public MyDialogFragment build(MyDialogFragment dialogFragment) {
        MyDialogFragment fragment = dialogFragment;
        Bundle bundle = new Bundle();
        bundle.putParcelable("builder", this);
        fragment.setArguments(bundle);
        return fragment;
    }

    public int getInterval() {
        return interval;
    }

    public BaseDialogBuilder setInterval(int interval) {
        this.interval = interval;
        return this;
    }

    public boolean isCancelOnTouch() {
        return cancelOnTouch;
    }

    public BaseDialogBuilder setCancelOnTouch(boolean cancelOnTouch) {
        this.cancelOnTouch = cancelOnTouch;
        return this;
    }

    public boolean getCover() {
        return cancelCover;
    }

    public BaseDialogBuilder setCover(boolean cover) {
        this.cancelCover = cover;
        return this;
    }

    public boolean isCancelCover() {
        return cancelCover;
    }

    public BaseDialogBuilder setCancelCover(boolean cancelCover) {
        this.cancelCover = cancelCover;
        return this;
    }

    public BaseDialogBuilder setTitle(String title) {
        this.title = title;
        return this;
    }

    public boolean isNeedAnimal() {
        return needAnimal;
    }

    public BaseDialogBuilder setNeedAnimal(boolean needAnimal) {
        this.needAnimal = needAnimal;
        return this;
    }

    public String getTitle() {
        return title;
    }

    public int getLayoutId() {
        return layoutId;
    }

    public BaseDialogBuilder setLayoutId(int layoutId) {
        this.layoutId = layoutId;
        return this;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.interval);
        dest.writeByte(this.cancelOnTouch ? (byte) 1 : (byte) 0);
        dest.writeByte(this.cancelCover ? (byte) 1 : (byte) 0);
        dest.writeInt(this.layoutId);
        dest.writeString(this.title);
        dest.writeByte(this.needAnimal ? (byte) 1 : (byte) 0);
    }

    protected BaseDialogBuilder(Parcel in) {
        this.interval = in.readInt();
        this.cancelOnTouch = in.readByte() != 0;
        this.cancelCover = in.readByte() != 0;
        this.layoutId = in.readInt();
        this.title = in.readString();
        this.needAnimal = in.readByte() != 0;
    }

}
